/*
 * 用户信息模块
 * @Author: ljb
 * @Date: 2018-04-11 18:02:05
 * @Last Modified by: ljb
 * @Last Modified time: 2018-08-29 17:11:58
 */
// import Vue from 'vue';
import { formaturl } from 'src/utils/utils';

const GENDER = {
	OTHER: 'OTHER',
	MALE: 'MALE',
	FEMALE: 'FEMALE',
};

const url_info = formaturl();

export default {
	namespaced: true,
	state: {

		is_inited: false, // 是否初始化数据完毕

		appid: null, // 公众号appid

		user_info: {},

	},
	mutations: {
		/* eslint-disable */
		setUserInfo(state, user_info) {
			state.user_info = user_info || {};
		},

		setAppid(state, appid) {
			state.appid = appid;

			sessionStorage.setItem('appid', appid);
		},

		initDataComplete(state) {
			state.is_inited = true;
		},
		/* eslint-enable */

		/**
		 * 设置阿里账号
		 * @param {object} state
		 * @param {*} ali_account
		 */
		setAliAccount(state, ali_account) {
			state.user_info.ali_account = ali_account;
		},
	},
	actions: {
		setUserPhone(context, phone) {
			if (context.state.user_info && context.state.user_info.phone) {
				context.state.user_info.phone = phone;
			}
		},

	},
	getters: {

		getUserInfo: state => state.user_info || {},

		getDataInitStatus: state => state.is_inited,

		getAppid: state => state.appid || url_info.app_id || '',

		/**
		 * 获取性别
		 * @return {String} FEMALE 或 MALE 或 OTHER
		 */
		getSex: (state) => {
			switch (state.user_info.sex) {
			case 1:

				return GENDER.MALE;
			case 2:

				return GENDER.FEMALE;

			default:
				return GENDER.OTHER;
			}
		},

	},
};
